{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 输出格式化\n",
    "* Python两种输出值的方式: 表达式语句和 print() 函数。\n",
    "* 第三种方式是使用文件对象的 write() 方法，标准输出文件可以用 sys.stdout 引用。\n",
    "* 如果你希望输出的形式更加多样，可以使用 str.format() 函数来格式化输出值。\n",
    "* 如果你希望将输出的值转成字符串，可以使用 repr() 或 str() 函数来实现。\n",
    "\n",
    "> str()： 函数返回一个用户易读的表达形式。\n",
    "\n",
    "> repr()： 产生一个解释器易读的表达形式。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'hello quant'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s='hello quant'\n",
    "str(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"'hello quant'\""
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "repr(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# str.format() \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "       1乘以       6等于                6\n",
      "      10乘以      60等于              600\n",
      "     100乘以     600等于            60000\n",
      "    1000乘以    6000等于          6000000\n",
      "   10000乘以   60000等于        600000000\n",
      "  100000乘以  600000等于      60000000000\n",
      " 1000000乘以 6000000等于    6000000000000\n",
      "10000000乘以60000000等于  600000000000000\n"
     ]
    }
   ],
   "source": [
    "for i in range(8):\n",
    "    x=10**i\n",
    "    y=x*6\n",
    "    print('{bcs:8d}乘以{cs:8d}等于{ji:17d}'.format(bcs=x,cs=y,ji=x*y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "常量PI值近似为：3.1416\n"
     ]
    }
   ],
   "source": [
    "print('常量PI值近似为：{:.4f}'.format(math.pi))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 括号及其里面的字符 (称作格式化字段) 将会被 format() 中的参数替换。\n",
    "* 在括号中的数字用于指向传入对象在 format() 中的位置。\n",
    "* 如果在 format() 中使用了关键字参数, 那么它们的值会指向使用该名字的参数。\n",
    "* 位置及关键字参数可以任意的结合。\n",
    "* 在 ':' 后传入一个整数, 可以保证该域至少有这么多的宽度。\n",
    "* 在 ':' 后传入一个.nf,可以是数值保持小数n位"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 读取键盘输入\n",
    "Python提供了 input() 内置函数从标准输入读入一行文本，默认的标准输入是键盘。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello quant\n",
      "hello quant\n"
     ]
    }
   ],
   "source": [
    "s=input()\n",
    "print(s)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
